package com.yang.news.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.yang.news.dao.entity.VisitLog;
import com.yang.news.dao.mapper.VisitLogMapper;
import com.yang.news.model.dto.VisitorCountDTO;
import com.yang.news.service.VisitLogService;
import org.springframework.stereotype.Service;

import java.util.Date;

/**
* @author Billyang
* @description 针对表【t_visit_log】的数据库操作Service实现
* @createDate 2024-11-29 10:53:44
*/
@Service
public class VisitLogServiceImpl extends ServiceImpl<VisitLogMapper, VisitLog>
    implements VisitLogService {

    @Override
    public int queryUvByStartTimeAndEndTime(Date startTime, Date entTime) {
        return this.baseMapper.queryUvByStartTimeAndEndTime(startTime, entTime);
    }

    @Override
    public int queryUv() {
        return this.baseMapper.queryUv();
    }

    @Override
    public VisitorCountDTO queryVisitorCount(Date startTime, Date endTime) {
        int todayPv = this.count(
                new QueryWrapper<VisitLog>().lambda().between(VisitLog::getCreateTime, startTime, endTime));
        int todayUv = this.queryUvByStartTimeAndEndTime(startTime, endTime);
        int allPv = this.count();
        int allUv = this.queryUv();
        return VisitorCountDTO.builder()
                .todayPv(todayPv)
                .todayUv(todayUv)
                .allPv(allPv)
                .allUv(allUv)
                .build();
    }
}




